﻿<cfsilent>
	<cfscript>
	
		jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice");
		
		teacherArray = arrayNew(1);
		rs_teacher = queryNew("tch_id");
		if ( event.isArgDefined('Keywords') AND len(event.getArg('Keywords')) ) {

			sql = "SELECT  a.tch_id, a.tch_name, 
						   a.tch_sex, b.institute_short 
					FROM t_teacher a  
						 INNER JOIN t_institute b ON b.institute_id = a.institute_id 
					WHERE 
						a.tch_id LIKE :keyword 
						OR 
						a.tch_name LIKE :keyword 
					ORDER BY a.tch_name ASC";
			queryObj = new Query( datasource=application.dnsSlave,maxRows=18 ); 
			queryObj.addParam( name="keyword", value=event.getArg('Keywords')&'%', cfsqltype="cf_sql_varchar" );
			rs_teacher= queryObj.execute( sql=sql ).getResult();
			
			for( a=1; a LTE rs_teacher.recordCount; a++ ){
				arrayAppend(teacherArray,[rs_teacher["tch_id"][a],rs_teacher["tch_name"][a],rs_teacher["tch_sex"][a],rs_teacher["institute_short"][a]]);
			}
		}
		
	</cfscript>
</cfsilent><cfoutput>#jsonAdvice.encode(data:teacherArray, stringNumbers:true)#</cfoutput>